//
//  ZMViewController.m
//  ZMHorizontalGridView
//
//  Created by babymingming on 09/13/2017.
//  Copyright (c) 2017 babymingming. All rights reserved.
//

#import "ZMViewController.h"
#import <ZMHorizontalGridView/ZMHorizontalGridView.h>
#import <Masonry/Masonry.h>
@interface ZMViewController ()<ZMHorizontalGridViewDataSource,ZMHorizontalGridViewDelegate>

@property(nonatomic,strong)ZMHorizontalGridView *horizontalGridView;

@end

@implementation ZMViewController{
    NSInteger _count;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _count = 11;//arc4random_uniform(100);
    NSLog(@"_count:%zd",_count);
    self.horizontalGridView = [ZMHorizontalGridView new];
    [self.view addSubview:self.horizontalGridView];
    
    [self.horizontalGridView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.width.equalTo(self.view);
        make.top.equalTo(self.view).offset(50);
        make.height.mas_equalTo(240);
    }];
    
    self.horizontalGridView.dataSource = self;
    self.horizontalGridView.delegate = self;
    
    [self.horizontalGridView reloadData];
    
    
}

#pragma mark
#pragma mark - 数据源方法
// 提供数量
- (NSInteger)numberOfItemsInHorizontalGridView:(ZMHorizontalGridView *_Nonnull)horizontalGridView {
    return _count;
}

// 提供图标路径
- (NSURL *_Nonnull)horizontalGridView:(ZMHorizontalGridView *_Nonnull)horizontalGridView
                    urlForItemAtIndex:(NSInteger)index {
    return [NSURL URLWithString:@"http://img4q.duitang.com/uploads/item/201503/11/20150311133307_NHJiF.jpeg"];
}

// 提供标题
- (NSString *_Nullable)horizontalGridView:(ZMHorizontalGridView *_Nonnull)horizontalGridView
                      titleForItemAtIndex:(NSInteger)index {
    return [NSString stringWithFormat:@"item %zd",index];
}


// 列数
-(NSInteger)numberOfColumsInHorizontalGridView:(ZMHorizontalGridView*)horizontalGridView {
    return 4;
}

// 行数
- (NSInteger)numberOfRowsInHorizontalGridView:(ZMHorizontalGridView *_Nonnull)horizontalGridView {
    return 2;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
